MongoDB-MongoDB重装系统后恢复

重装系统后,把原mongoDB安装目录和原mongoDB的data目录拷贝到新硬盘的D盘上。

恢复的方法如下。

1、D:\Mongodb里放着mongod.cfg和data

C:\Users\Administrator>dir D:\Mongodb
驱动器 D 中的卷没有标签。
卷的序列号是 A48D-4D74

D:\Mongodb 的目录

2017/05/06 21:48 <DIR> .
2017/05/06 21:48 <DIR> ..
2017/05/06 21:48 <DIR> data
2017/03/19 19:57 110 mongod.cfg
1 个文件 110 字节
3 个目录 1,017,095,073,792 可用字节

其中mongod.cfg中内容如下:

systemLog:
destination: file
path: D:\Mongodb\data\log\mongod.log
storage:
dbPath: D:\Mongodb\data\db

2、打开cmd。执行

C:\Users\Administrator>"D:\Program Files\mongodb-win32-i386-3.0.7\bin\mongod.exe
" --config D:\Mongodb\mongod.cfg --install
2017-05-07T15:07:18.761+0800 I CONTROL
2017-05-07T15:07:18.763+0800 W CONTROL 32-bit servers don't have journaling ena
bled by default. Please use --journal if you want durability.
2017-05-07T15:07:18.763+0800 I CONTROL
2017-05-07T15:07:18.766+0800 I CONTROL log file "D:\Mongodb\data\log\mongod.log
" exists; moved to "D:\Mongodb\data\log\mongod.log.2017-05-07T07-07-18".

C:\Users\Administrator>net start MongoDB

MongoDB 服务已经启动成功。

这个时候,在系统里可以看到mongodb的服务了。

3、测试下原来的数据还在不在。打开pycharm中mongodb的mongodb控件。做连接测试,发现连接超时。回到服务里,发现mongodb状态是停止的。于是打开日志文件D:\Mongodb\data\log,有如下的报错

2017-05-07T15:23:33.144+0800 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out data files
2017-05-07T15:23:33.147+0800 I CONTROL Trying to start Windows service 'MongoDB'
2017-05-07T15:23:33.148+0800 I STORAGE Service running
2017-05-07T15:23:33.149+0800 W - [initandlisten] Detected unclean shutdown - D:\Mongodb\data\db\mongod.lock is not empty.
2017-05-07T15:23:33.163+0800 I STORAGE [initandlisten] **************
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
2017-05-07T15:23:33.166+0800 I STORAGE [initandlisten] exception in initAndListen: 12596 old lock file, terminating
2017-05-07T15:23:33.166+0800 I CONTROL [serviceStopWorker] dbexit: rc: 49

查询了下,于是进入D:\Program Files\mongodb-win32-i386-3.0.7\bin目录下,执行mongodb-win32-i386-3.0.7\bin>mongod --repair --dbpath D:\Mongodb\data\db

D:\Program Files\mongodb-win32-i386-3.0.7\bin>mongod --repair --dbpath D:\Mongodb\data\db
2017-05-07T15:25:34.931+0800 I CONTROL
2017-05-07T15:25:34.932+0800 W CONTROL 32-bit servers don't have journaling ena
bled by default. Please use --journal if you want durability.
2017-05-07T15:25:34.934+0800 I CONTROL
2017-05-07T15:25:34.940+0800 I CONTROL Hotfix KB2731284 or later update is not....

再重新net start MongoDB。进入服务,发现状态是已启动,再做连接测试,OK。查询数据,也还在!

4、总结下,要做数据恢复。mongodb 32位可以直接在64位windows下用,而且拷过来就行,不用安装。

posted @ 2017-05-07 15:18  .每天进步一点点  阅读(2267)  评论(0编辑  收藏  举报